package pl.edu.agh.mguesser.ui.game;

import java.awt.BorderLayout;
import javax.annotation.PostConstruct;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import org.springframework.stereotype.Controller;
import pl.edu.agh.mguesser.game.listener.GameStartedListener;
import pl.edu.agh.mguesser.game.listener.TimeTickingListener;
import pl.edu.agh.mguesser.game.stop.StopRequestHandler;

/**
 * @author keiran
 */
@Controller
public class SongProgressPanel extends JPanel implements GameStartedListener,
                                                         TimeTickingListener {
    
    private static final int MAX_SECONDS 
            = StopRequestHandler.DEFAULT_TIMEOUT / 1000;

    private JProgressBar songProgressBar;
    private JLabel songProgressLabel;
    
    @PostConstruct
    public void postConstruct() {
        setLayout(new BorderLayout());
        
        songProgressBar = new JProgressBar(0, MAX_SECONDS);
        songProgressLabel = new JLabel("");
        
        add(songProgressBar, BorderLayout.CENTER);
        add(songProgressLabel, BorderLayout.SOUTH);
    }

    @Override
    public void gameStarted() {
        songProgressBar.setValue(0);
        songProgressLabel.setText("");
    }

    @Override
    public void tick(int second) {
        songProgressBar.setValue(second);
        songProgressLabel.setText("SECONDS: " + second + " / " + MAX_SECONDS);
    }

}
